<?php
class ApiStatisticController extends ApiController
{
  public function friendRankAction()
  {
    $statisticModel = $this->getModel('statistic');
    $page = max(intval($this->req->getQueryTrim('page', 1)), 1);
    $rows = intval($this->req->getQueryTrim('rows', 15));
    return $this->okReturn([
     'list' => $statisticModel->getFriendRankList($this->account->player_id, $page, $rows),
     'rank' => $statisticModel->getFriendRank($this->account->player_id)
    ]);
  }

  public function allRankAction()
  {
   $statisticModel = $this->getModel('statistic');
    $page = max(intval($this->req->getQueryTrim('page', 1)), 1);
    $rows = intval($this->req->getQueryTrim('rows', 15));
    return $this->okReturn([
     'list' => $statisticModel->getAllRankList($page, $rows),
     'rank' => $statisticModel->getAllRank($this->account->player_id)
    ]);
  }

  public function last7Action()
  {
    $statisticModel = $this->getModel('statistic');
    return $this->okReturn($statisticModel->last7Flower($this->account->player_id));
  }

  public function reportAction()
  {
    $statisticModel = $this->getModel('statistic');
    $lastWeek = date('YW', REQUEST_TIME - 604800);
    return $this->okReturn([
      'visitor' => $this->account->getVisitorWeekCount($lastWeek),
      'flowers' => $this->account->getflowersWeekCount($lastWeek),
      'allrank' => $statisticModel->getAllRank($this->account->player_id),
    ]);
  }

}